export const MESSAGES={WIN:"Вы угадали!",LESS_THAN_CURRENT:"Загаданное число меньше вашего",GREATER_THAN_CURRENT:"Загаданное число больше вашего",OUT_OF_BOUNDARIES:(e,t)=>`Число должно быть в диапазоне от ${e} до ${t}`};export const DOM_IDS={GUESS_FORM:"guess-form",GUESS_INPUT:"guess-input",GUESS_SUBMIT:"guess-submit",ATTEMPTS_ITEMS:"attempts-items",ATTEMPTS_COUNT:"attempts-count",MESSAGE:"message",HINT:"hint",RESTART_BTN:"restart",SETTINGS_BTN:"settings",SETTINGS_MENU:"settings-menu",MIN_NUMBER_INPUT:"min-number-input",MAX_NUMBER_INPUT:"max-number-input"};export const getRandomNumber=(e,t)=>Math.floor(Math.random()*(t-e+1))+e;export const isNumber=e=>!isNaN(parseInt(e));export const updateElementText=(e,t)=>{let n=document.getElementById(e);n&&(n.textContent=t)};export const clearInput=e=>{let t=document.getElementById(e);t&&(t.value="")};export const saveAttempt=e=>{let t=document.getElementById(DOM_IDS.ATTEMPTS_ITEMS);if(t){let n=document.createElement("div");n.textContent=+e,t.append(n)}};export const clearAttempts=()=>{let e=document.getElementById(DOM_IDS.ATTEMPTS_ITEMS);e&&(e.innerHTML="")};export const updateAttemptsCount=e=>{let t=document.getElementById(DOM_IDS.ATTEMPTS_COUNT);t&&(t.textContent=`Ваши попытки (${e}): `)};export const showHint=e=>{let t=document.getElementById(DOM_IDS.HINT);t&&!t.classList.contains("visible")&&(t.textContent=e,t.classList.add("visible"),setTimeout(()=>{t.classList.remove("visible")},3e3))};export const hideHint=()=>{let e=document.getElementById(DOM_IDS.HINT);e&&e.classList.contains("visible")&&e.classList.remove("visible")};export const disableInput=()=>{document.getElementById(DOM_IDS.GUESS_INPUT).disabled=!0,document.getElementById(DOM_IDS.GUESS_SUBMIT).disabled=!0};export const enableInput=()=>{document.getElementById(DOM_IDS.GUESS_INPUT).disabled=!1,document.getElementById(DOM_IDS.GUESS_SUBMIT).disabled=!1};let DEFAULT_MIN_NUMBER=1,DEFAULT_MAX_NUMBER=100,gameModel={isWin:!1,attempts:0,minNumber:1,maxNumber:100,targetNumber:getRandomNumber(1,100),OUT_OF_BOUNDARIES_MESSAGE:MESSAGES.OUT_OF_BOUNDARIES(1,100),checkGuess(e){return(this.attempts++,parseInt(e)===this.targetNumber)?(this.isWin=!0,MESSAGES.WIN):e>this.targetNumber?MESSAGES.LESS_THAN_CURRENT:MESSAGES.GREATER_THAN_CURRENT},isTargetNumberEven(){return this.targetNumber%2==0}},checkGuess=(e,t)=>{if(!isNumber(e)){updateElementText(DOM_IDS.MESSAGE,"Введите корректное число");return}let n=e>=t.minNumber&&e<=t.maxNumber;if(!n){updateElementText(DOM_IDS.MESSAGE,t.OUT_OF_BOUNDARIES_MESSAGE);return}let s=t.checkGuess(e),r=t.attempts%3==0;updateElementText(DOM_IDS.MESSAGE,s),saveAttempt(e),updateAttemptsCount(t.attempts),clearInput(DOM_IDS.GUESS_INPUT),t.isWin?disableInput():r&&showHint(`Загаданное число ${t.isTargetNumberEven()?"четное":"нечетное"}`)},restartGame=(e,t,n)=>{let s=isNumber(e),r=isNumber(t),S=+e<+t;if(!s||!r||!S){updateElementText(DOM_IDS.MESSAGE,"Введите корректный диапазон чисел");return}n.isWin=!1,n.attempts=0,n.minNumber=+e,n.maxNumber=+t,n.targetNumber=getRandomNumber(n.minNumber,n.maxNumber),n.OUT_OF_BOUNDARIES_MESSAGE=MESSAGES.OUT_OF_BOUNDARIES(n.minNumber,n.maxNumber),updateElementText(DOM_IDS.MESSAGE,`Я загадал число от ${n.minNumber} до ${n.maxNumber}, попробуйте его отгадать`),updateElementText(DOM_IDS.ATTEMPTS_COUNT,""),clearAttempts(),hideHint(),updateElementText(DOM_IDS.HINT,""),clearInput(),enableInput()},gameView={updateElementText,clearInput,saveAttempt,clearAttempts,updateAttemptsCount,showHint,hideHint},gameController={disableInput,enableInput,handleGuess:e=>checkGuess(e,gameModel,gameView,gameController),restartGame:(e,t)=>restartGame(e,t,gameModel,gameView,gameController)},restartButton=document.querySelector(`#${DOM_IDS.RESTART_BTN}`),settingsButton=document.querySelector(`#${DOM_IDS.SETTINGS_BTN}`),settingsMenu=document.querySelector(`#${DOM_IDS.SETTINGS_MENU}`),minNumberInput=settingsMenu.querySelector(`#${DOM_IDS.MIN_NUMBER_INPUT}`),maxNumberInput=settingsMenu.querySelector(`#${DOM_IDS.MAX_NUMBER_INPUT}`),guessForm=document.querySelector(`#${DOM_IDS.GUESS_FORM}`);guessForm.addEventListener("submit",e=>{e.preventDefault();let t=document.querySelector(`#${DOM_IDS.GUESS_INPUT}`).value;gameController.handleGuess(t)}),settingsButton.addEventListener("click",()=>{settingsButton.classList.toggle("active"),settingsMenu.classList.toggle("visible")}),restartButton.addEventListener("click",()=>{gameController.restartGame(minNumberInput.value,maxNumberInput.value)});